# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Robin Broda <robin at broda dot me>

pkgname=bonzomatic
pkgver=1.0.20220820
pkgrel=1
pkgdesc='Live shader coding tool'
arch=(loong64 x86_64)
url='https://github.com/Gargaj/bonzomatic'
license=(Custom:Unlicense)
depends=(alsa-lib fontconfig hicolor-icon-theme libglvnd)
makedepends=(chrpath cmake git glu imagemagick libxcursor libxi libxinerama libxrandr ninja)
source=("$pkgname::git+$url#commit=b74363c602614460f2b5ea51b99c5f1096333407") # tag: 2022-08-20
b2sums=(SKIP)

prepare() {
  convert "$pkgname/data/unix/icon.png" -resize 128x128 "$srcdir/$pkgname.png"
}

build() {
  cmake \
    -B build \
    -D CMAKE_C_FLAGS="$CFLAGS -fPIC -w" \
    -D CMAKE_CXX_FLAGS="$CFLAGS -fPIC -w" \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -G Ninja \
    -S $pkgname
  ninja -C build
}

package() {
  DESTDIR="$pkgdir" ninja -C build install

  # Fix insecure rpath
  chrpath -d "$pkgdir/usr/bin/bonzomatic"

  # Package license
  install -Dm644 $pkgname/LICENSE \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # Package desktop icon
  install -Dm644 $pkgname.png "$pkgdir/usr/share/pixmaps/$pkgname.png"
}
